home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 1 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.1 KB  |  80 lines

  1. Newsgroups: comp.std.c++
  2. Path: cs.mu.OZ.AU!bounce-back
  3. From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
  4. Subject: Re: Nested template class definitions
  5. Message-ID: <9600116.2625@mulga.cs.mu.OZ.AU>
  6. Originator: fjh@munta.cs.mu.OZ.AU
  7. Sender: news@cs.mu.OZ.AU (CS-Usenet)
  8. Organization: Computer Science, University of Melbourne, Australia
  9. References: <4c525e$one@nnrp1.news.primenet.com>
  10. Date: Mon, 1 Jan 1996 05:17:06 GMT
  11. Approved: fjh@cs.mu.oz.au
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBFAgUBMOduceEDnX0m9pzZAQFY7QF9EK70iYw0dM1WRzxowozcKIHOURPausyf
  14.     Fz1flfvdQjfoh4kmmJejApKZrgNH9I71
  15.     =Zgbg
  16.  
  17. Robert DiFalco <difalco@primenet.com> writes:
  18.  
  19. >How do I define a nested class in a template?
  20.  
  21. You can define it either inline in the outer class declaration, or you
  22. can just declare it in the outer class declaration and define it
  23. later.  The latter method was allowed only relatively recently, and so
  24. not all compilers support it yet.
  25.  
  26. >It seems to me that logic could offer this:
  27. >
  28. >   template <class Item>
  29. >   class List_
  30. >   {
  31. >      public:
  32. >         .
  33. >         .
  34. >         .
  35. >         class Iterator;
  36. >   };
  37. >
  38. >
  39. >   template <class Item>
  40. >   class List_<Item>::Iterator : public CollectionIterators_<Item>
  41. >   {
  42. >      .
  43. >      .
  44. >      .
  45. >   };
  46.  
  47. Yep, that is exactly right.
  48.  
  49. >However, in Visual C++ 4.0, this produces the painfully ambiguous error
  50. >message "error C2988: unrecognizable template declaration/definition".
  51. >
  52. >So, what gives? Is this an MSVC 4.0 problem, or am I use the incorrect
  53. >syntax for defining a nested class outside of the outer classes scope?
  54.  
  55. It is an MSCV 4.0 problem.
  56.  
  57. As a work-around, try the following structure instead.
  58.  
  59.    template <class Item>
  60.    class List_
  61.    {
  62.       public:
  63.          .
  64.          .
  65.          .
  66.          class Iterator {
  67.         .
  68.         .
  69.         .
  70.     };
  71.    };
  72.  
  73. --
  74. Fergus Henderson                 WWW: http://www.cs.mu.oz.au/~fjh
  75. fjh@cs.mu.oz.au                  PGP: finger fjh@128.250.37.3
  76. ---
  77. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  78.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  79.   is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
  80.